<?php

/**
 * MyProjectNameHere <http://www.example.com>
 * Model Class
 *
 * It is recommended to extend Model classes from WWW_Factory in order to 
 * provide various useful functions and API access for the Model.
 *
 * @package    Factory
 * @author     DeveloperNameHere <email@example.com>
 * @copyright  Copyright (c) 2012, ProjectOwnerNameHere
 * @license    Unrestricted
 * @tutorial   /doc/pages/guide_mvc.htm
 * @since      1.0.0
 * @version    1.0.0
 */

class WWW_model_megaphones extends WWW_Factory {

	/**
	 * It is recommended to define all data variables here. Usually the 
	 * data variables have the same names as the column names of database 
	 * rows from a table.
	 */	
	public $conn;
	/**
	 * Alternative to __construct()
	 *
	 * WWW_Factory does not allow to overwrite __construct() method, so 
	 * this __initialize() is used instead and loaded automatically when 
	 * object is created.
	 *
	 * @return boolean
	 */
	public function __initialize(){
		require('engine/class.www-database.php');
		$this->conn=new WWW_Database();				
		return true;
		
	}
	public function create_megaphone($data){
		
	$query="insert into `megaphone` (megaphone_title,megaphone_displayorder,megaphone_starton,megaphone_expireon,megaphone_content,megaphone_image,created_date,updated_date) VALUES ('".$data['megaphone_title']."','".$data['megaphone_displayorder']."','".date($data['megaphone_starton'])."','".date($data['megaphone_expireon'])."','".$data['megaphone_content']."','".$data['megaphone_image']."','".date("Y-m-d H:i:s")."','".date("Y-m-d H:i:s")."')";
	//print_r($query);exit;
	$result=$this->conn->dbCommand($query);	
		if($result){
			return array('message'=>'Top stories successfully created');			
		}else{
			return array('message'=>'Top stories Creation Failed');
		}	
	}
	public function edit_megaphone($data){
	$query="update `megaphone` set megaphone_title='".$data['megaphone_title']."',megaphone_displayorder='".$data['megaphone_displayorder']."',megaphone_starton='".$data['megaphone_starton']."',megaphone_expireon='".$data['megaphone_expireon']."',megaphone_content='".$data['megaphone_content']."',megaphone_image='".$data['megaphone_image']."',updated_date='".date("Y-m-d H:i:s")."' where megaphone_id=".$data['megaphone_id'];
		//print_r($query);exit;
		$result=$this->conn->dbCommand($query);		
		if($result){
			return array('message'=>'Top stories Updated Successfully');			
		}else{
			return array('message'=>'Top stories Updates Failed');
		}	
	
	}
	public function get_megaphone($data)
	{	
	echo "<pre>";print_r($data);exit;
		 $query="SELECT megaphone_title,megaphone_displayorder,megaphone_starton,megaphone_expireon,megaphone_content,megaphone_image from megaphone
where megaphone_id=".$data['megaphone_id'];
			
		$result=$this->conn->dbMultiple($query);		
		if($result){
			return array('message'=>'Top stories get Successfully', 'result'=>$result);			
		}else{
			return array('message'=>'Top stories get Failed');
		}	
		
	}
	public function delete_megaphone($data){
		$data=$this->conn->dbCommand("update `megaphone` set status='".$data['status']."' where megaphone_id=".$data['megaphone_id']);
		if($data)
			return array('message'=>"Top stories Deleted Successfully");		
		else
			return array('message'=>'Top stories Deletion Fails');
	}
	public function all_megaphones($data){
		$current_page=0;
	$results_per_page=10;
	$order_by="created_date";
	$sort_order="desc";
	if(isset($data['order_by']) && $data['order_by']!='')
	{
		$order_by=$data['order_by'];
	}
	if(isset($data['results_per_page']) && $data['sort_order']!='')
	{
		$sort_order=$data['sort_order'];
	}
	if(isset($data['current_page'])&& $data['current_page']!='' || $data['current_page']!=0)
	{
	$current_page=$data['current_page'];
	}
	if(isset($data['results_per_page']) && $data['results_per_page']!='' || $data['results_per_page']!=0){
	$results_per_page=$data['results_per_page'];
	}
	$offset=$current_page;
	
	}

}
?>